<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 
  Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="EpsonScanSDK.js"></script>
    <script language="javascript" type="text/javascript">
        current_count = 1;
        current_fileFormat = ESLFunctions.FF_JPEG;

        function ScanAndSaveButtonClick() 
        {

            var connectionParam = {};
            connectionParam.deviceName = "DS-530II";
            connectionParam.connectType = 0;
            var scanParams = {};
            scanParams.docSource = ESLFunctions.SRC_AUTO;  
            scanParams.imgType = ESLFunctions.IT_AUTO;
            scanParams.resolution = 200;
            scanParams.docSize = ESLFunctions.DS_AUTO;
            scanParams.docRotate = ESLFunctions.DR_NONE;
            scanParams.brightness = 0;
            scanParams.contrast = 0;
            scanParams.threshold = 126;
            scanParams.colorFilter = ESLFunctions.CF_NONE;
            scanParams.numScan = 0;//ALL
            scanParams.docEnhance = 0;
            scanParams.imgFilter = 0;
            scanParams.optDoubleFeedDetect = ESLFunctions.DFD_NONE;
            scanParams.optBlankPageSkip = ESLFunctions.BPS_NONE;
            scanParams.skewCorrect = ESLFunctions.SC_EDGE;

            
            var saveParam = {};
            saveParam.destination = ESLFunctions.DEST_BASE64;
            saveParam.fileFormat = current_fileFormat;

            var eslObj = ESLFunctions.ESLCreate();
            eslObj.ScanAndSave_Simple(connectionParam, scanParams, saveParam,  function(isSuccess, result){
                if (isSuccess)
                {
                    if (result.eventType == ESLFunctions.EVENT_SCANPAGE_COMPLETE)
                    {
                        writeLog("scan page complete");
                    }
                    if (result.eventType == ESLFunctions.EVENT_ALLSCAN_COMPLETE)
                    {
                        writeLog("all scan page complete");
                    }
                    if (result.eventType == ESLFunctions.EVENT_SAVEPAGE_COMPLETE)
                    {   
                        viewFile(result.base64);
                    }
                    if (result.eventType == ESLFunctions.EVENT_ALLSAVE_COMPLETE)
                    {
                        writeLog("all save page complete");
                    }
                }else{
                    writeLog("scan request fail error = " + result.errorCode.toString(16));
                }
            });
        }
        function GetInfoFromScannerClick() 
        {
            var connectionParam = {};
            connectionParam.deviceName = "DS-530II";
            connectionParam.connectType = 0;

            var eslObj = ESLFunctions.ESLCreate();
            eslObj.Open(connectionParam, function(isSuccess, result){
                if (isSuccess == true)
                {
                    writeLog("Open success");

                    eslObj.GetInfo(function(isSuccess, result){
                            if (isSuccess == true)
                            {
                                writeLog("GetInfo success");
                                writeLog("serialNumber =" + result.serialNumber);

                            }else{
                                writeLog("GetInfo fail");
                            }
                            eslObj.Close(function(isSuccess, result){});
                        }
                    );
                }
            });
            
        }
        function writeLog(message) {
            var log = document.getElementById('log');
            log.value += message + "\n";
            log.scrollTop = log.scrollHeight;
        }

        function viewFile(base64)
        {
            var link = document.createElement('a');
            if (current_fileFormat == ESLFunctions.FF_PDF)
            {
                link.download = 'file'+current_count+'.pdf';
            }
            if (current_fileFormat == ESLFunctions.FF_JPEG)
            {
                link.download = 'file'+current_count+'.jpg';
            }
            if (current_fileFormat == ESLFunctions.FF_MULTITIFF)
            {
                link.download = 'file'+current_count+'.tif';
            }
            if (current_fileFormat == ESLFunctions.FF_TIFF)
            {
                link.download = 'file'+current_count+'.tif';
            }
            if (current_fileFormat == ESLFunctions.FF_BMP)
            {
                link.download = 'file'+current_count+'.bmp';
            }
            link.innerHTML = link.download;
            link.href = 'data:application/octet-stream;base64,' + base64;

            var downloadArea = document.getElementById('downloadarea');

            document.body.insertBefore(document.createElement('br'), downloadArea);
            document.body.insertBefore(link, downloadArea);

            current_count+=1;
        }
    </script>
</head>
<body>
    <h3> Epson Scan SDK Web Extension Sample </h3>
    <br />
    <input type="button" id="open" value="Scan and Save" onclick="ScanAndSaveButtonClick();"/><br />
    <br />
    <input type="button" id="getinfo" value="GetInfo from scanner" onclick="GetInfoFromScannerClick();"/><br />
    <br />
    <div id="downloadarea">
    </div>
    <textarea id="log"  cols="30" rows="50"  readonly></textarea>
    <br />
</body>
</html>